home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
ada
/
c01lab4.zip
/
LRMRDR
/
LRM_CHAP.ZIP
/
CHAP11.DOC
< prev
next >
Wrap
Text File
|
1992-04-21
|
35KB
|
816 lines
> 11. Exceptions
This chapter defines the facilities for dealing with errors or other
exceptional situations that arise during program execution. Such a
situation is called an exception. To raise an exception is to abandon
normal program execution so as to draw attention to the fact that the
corresponding situation has arisen. Executing some actions, in response to
the arising of an exception, is called handling the exception.
An exception declaration declares a name for an exception. An exception
can be raised by a raise statement, or it can be raised by another
statement or operation that propagates the exception. When an exception
arises, control can be transferred to a user-provided exception handler at
the end of a block statement or at the end of the body of a subprogram,
package, or task unit.
References: block statement 5.6, error situation 1.6, exception handler
11.2, name 4.1, package body 7.1, propagation of an exception 11.4.1
11.4.2, raise statement 11.3, subprogram body 6.3, task body 9.1
> 11.1 Exception Declarations
An exception declaration declares a name for an exception. The name of an
exception can only be used in raise statements, exception handlers, and
renaming declarations.
exception_declaration ::= identifier_list : exception;
An exception declaration with several identifiers is equivalent to a
sequence of single exception declarations, as explained in section 3.2.
Each single exception declaration declares a name for a different
exception. In particular, if a generic unit includes an exception
declaration, the exception declarations implicitly generated by different
instantiations of the generic unit refer to distinct exceptions (but all
have the same identifier). The particular exception denoted by an
exception name is determined at compilation time and is the same regardless
of how many times the exception declaration is elaborated. Hence, if an
exception declaration occurs in a recursive subprogram, the exception name
denotes the same exception for all invocations of the recursive subprogram.
The following exceptions are predefined in the language; they are raised
when the situations described are detected.
CONSTRAINT_ERROR This exception is raised in any of the following
situations: upon an attempt to violate a range
constraint, an index constraint, or a discriminant
constraint; upon an attempt to use a record component
that does not exist for the current discriminant values;
and upon an attempt to use a selected component, an
indexed component, a slice, or an attribute, of an object
designated by an access value, if the object does not
exist because the access value is null.
NUMERIC_ERROR This exception is raised by the execution of a predefined
numeric operation that cannot deliver a correct result
(within the declared accuracy for real types); this
includes the case where an implementation uses a
predefined numeric operation for the execution,
evaluation, or elaboration of some construct. The rules
given in section 4.5.7 define the cases in which an
implementation is not required to raise this exception
when such an error situation arises; see also section
11.6.
PROGRAM_ERROR This exception is raised upon an attempt to call a
subprogram, to activate a task, or to elaborate a generic
instantiation, if the body of the corresponding unit has
not yet been elaborated. This exception is also raised
if the end of a function is reached (see 6.5); or during
the execution of a selective wait that has no else part,
if this execution determines that all alternatives are
closed (see 9.7.1). Finally, depending on the
implementation, this exception may be raised upon an
attempt to execute an action that is erroneous, and for
incorrect order dependences (see 1.6).
STORAGE_ERROR This exception is raised in any of the following
situations: when the dynamic storage allocated to a task
is exceeded; during the evaluation of an allocator, if
the space available for the collection of allocated
objects is exhausted; or during the elaboration of a
declarative item, or during the execution of a subprogram
call, if storage is not sufficient.
TASKING_ERROR This exception is raised when exceptions arise during
intertask communication (see 9 and 11.5).
Note:
The situations described above can arise without raising the corresponding
exceptions, if the pragma SUPPRESS has been used to give permission to omit
the corresponding checks (see 11.7).
Examples of user-defined exception declarations:
SINGULAR : exception;
ERROR : exception;
OVERFLOW, UNDERFLOW : exception;
References: access value 3.8, collection 3.8, declaration 3.1, exception
11, exception handler 11.2, generic body 12.2, generic instantiation 12.3,
generic unit 12, identifier 2.3, implicit declaration 12.3, instantiation
12.3, name 4.1, object 3.2, raise statement 11.3, real type 3.5.6, record
component 3.7, return statement 5.8, subprogram 6, subprogram body 6.3,
task 9, task body 9.1
Constraint_error exception contexts: aggregate 4.3.1 4.3.2, allocator 4.8,
assignment statement 5.2 5.2.1, constraint 3.3.2, discrete type attribute
3.5.5, discriminant constraint 3.7.2, elaboration of a generic formal
parameter 12.3.1 12.3.2 12.3.4 12.3.5, entry index 9.5, exponentiating
operator 4.5.6, index constraint 3.6.1, indexed component 4.1.1, logical
operator 4.5.1, null access value 3.8, object declaration 3.2.1, parameter
association 6.4.1, qualified expression 4.7, range constraint 3.5, selected
component 4.1.3, slice 4.1.2, subtype indication 3.3.2, type conversion 4.6
Numeric_error exception contexts: discrete type attribute 3.5.5, implicit
conversion 3.5.4 3.5.6 4.6, numeric operation 3.5.5 3.5.8 3.5.10, operator
of a numeric type 4.5 4.5.7
Program_error exception contexts: collection 3.8, elaboration 3.9,
elaboration check 3.9 7.3 9.3 12.2, erroneous 1.6, incorrect order
dependence 1.6, leaving a function 6.5, selective wait 9.7.1
Storage_error exception contexts: allocator 4.8
Tasking error exception contexts: abort statement 9.10, entry call 9.5
9.7.2 9.7.3, exceptions during task communication 11.5, task activation 9.3
> 11.2 Exception Handlers
The response to one or more exceptions is specified by an exception
handler.
exception_handler ::=
when exception_choice {| exception_choice} =>
sequence_of_statements
exception_choice ::= exception_name | others
An exception handler occurs in a construct that is either a block statement
or the body of a subprogram, package, task unit, or generic unit. Such a
construct will be called a frame in this chapter. In each case the syntax
of a frame that has exception handlers includes the following part:
begin
sequence_of_statements
exception
exception_handler
{exception_handler}
end
The exceptions denoted by the exception names given as exception choices of
a frame must all be distinct. The exception choice others is only allowed
for the last exce